package com.springapp.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

/**
 * @author Tandan
 * @Date 17-3-22
 * @see
 */
public class ShellUtil {

    public static void main(String[] args) throws Exception{
        Runtime rt = Runtime.getRuntime();
        Process p = null;
        String comm = "%Githubconfig%";
        p = rt.exec(comm);
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println( line ) ;

        }

    }

    public static boolean execCommoned (String[] comm,  File fullPath) throws Exception{
        String osName = System.getProperty("os.name");
        boolean flag = false;
        try {
            if(false
                    /*!(osName.equalsIgnoreCase("windows XP") || osName.equalsIgnoreCase("windows 2000") || osName.equalsIgnoreCase("windows 2003") || osName.equalsIgnoreCase("windows 7"))*/){
                //linux
            }else{
                //window
                Runtime rt = Runtime.getRuntime();
                Process p = null;
                int exitVal;
                //File file = new File(fullPath);
                p = rt.exec(comm, null ,fullPath);
                exitVal = p.waitFor();
                if(exitVal == 0){
                    flag = true;
                }else{
                    flag = false;
                }

            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return flag;
    }

}